<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>实现多组件的过渡效果</title>
    <!--引入Vue库-->
    <script src="vue.js"></script>
    <style>
      .fade-enter,
      .fade-leave-to {
        opacity: 0;
      }
      .fade-enter-active,
      .fade-leave-active {
        transition: 0.5s;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button @click="change">切换页面</button>
      <transition name="fade" mode="out-in">
        <component :is="currentView"></component>
      </transition>
    </div>
    <script>
      new Vue({
        el: "#app",
        data: {
          index: 0,
          arr: [
            { template: `<div>主页面</div>` },
            { template: `<div>登录页面</div>` },
            { template: `<div>注册页面</div>` },
          ],
        },
        computed: {
          currentView() {
            return this.arr[this.index];
          },
        },
        methods: {
          change() {
            this.index = ++this.index % 3;
          },
        },
      });
    </script>
  </body>
</html>
